--[[

LL_Functions.lua

Required functions for addon.

These functions will be overridden by the LCT_Shared_Library addon if installed.

NOTE: These functions will NOT be updated unless very obvious bugs are found.  This means installed LCT_Shared_Library is the ONLY way to get the latest versions of these functions.

NOTE2: Any other addons that use these functions will randomly chose between these functions and the updated functions.

]]

LCT_Shared_COLOURS = {
	["GREY"]        = "|c00909090",
	["BRIGHTGREY"]  = "|c00D0D0D0",
	["WHITE"]       = "|c00FFFFFF",
	["GREEN"]		= "|c0000FF00",
	["GOLD"]		= "|c00FFD100",
	["SILVER"]		= "|c00e6e6e6",
	["COPPER"]		= "|c00c8602c",
	["NORMAL"]		= "|r",
	["YELLOW"]		= "|c00FFFF00",
	["RED"]			= "|c00FF0000",
	["BLUE"]		= "|c000000FF",
	["LIGHTBLUE"]	= "|c007070FF",
};

-- Function: Find out the real player name, that is player+realm
function LCT_Shared_GetPlayerRealmName()
	local realmName = GetCVar("realmName");

	local playerName = UnitName("player");
	if ((playerName ~= nil) and (playerName ~= UNKNOWNOBJECT) and (playerName ~= UKNOWNBEING)) then
		return realmName.."."..playerName;
	end

	return "unknown";
end

-- Function: Help display routine
function LCT_Shared_Display_Help(helpTextVariable)
	local index = 0;
	local value = getglobal(helpTextVariable..index);
	while( value ) do
		DEFAULT_CHAT_FRAME:AddMessage(value);
		index = index + 1;
		value = getglobal(helpTextVariable..index);
	end
end

--------------------------------------------------------------------------------------------------
-- These functions have been taken from other addons - no use re-inventing the wheel.
-- Especially as I did not want to rely on those addons myself - in the future these
-- will be replaced by functions re-written by myself as this addon is too simple to need
-- these extra functions...
--------------------------------------------------------------------------------------------------

function LCT_Shared_Split(toCut, separator)
	local splitted = {};
	local i = 0;
	local regEx = "([^" .. separator .. "]*)" .. separator .. "?";

	for item in string.gmatch(toCut .. separator, regEx) do
		i = i + 1;
		splitted[i] = string.gsub(item, "^%s*(.-)%s*$", "%1") or '';
	end
	splitted[i] = nil;
	return splitted;
end
